# Contributor: prymeroot <pryme@gmx.com>
# Contributor: Jeff Bilyk <jbilyk@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=fail2ban
pkgver=0.11.1
pkgrel=3
pkgdesc="Scans log files for login failures then updates iptables to reject originating ip address"
url="https://www.fail2ban.org"
arch="noarch !s390x" # test failures
license="GPL-2.0-or-later"
depends="python3 iptables ip6tables logrotate"
makedepends="python3-dev py3-setuptools bash"
subpackages="$pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/fail2ban/fail2ban/archive/$pkgver.tar.gz
		ec37b1942c4da76f7a0f71efe81bea6835466648.patch
		0001-amend-to-f3dbc9dda10e52610e3de26f538b5581fd905505-ch.patch
		fail2ban.confd
		fail2ban.logrotate
		alpine-ssh.jaild
		alpine-sshd.filterd
		alpine-sshd-ddos.filterd
		"
case "$CARCH" in
	mips64|armhf) options="!check";;
esac

build() {
	sh fail2ban-2to3
	python3 setup.py build
}

check() {
	python3 setup.py test
}

package() {
	python3 setup.py install --root "$pkgdir"

	install -Dm755 files/gentoo-initd "$pkgdir"/etc/init.d/fail2ban
	install -Dm644 "$srcdir"/fail2ban.confd "$pkgdir"/etc/conf.d/fail2ban
	install -Dm644 "$srcdir"/fail2ban.logrotate \
		"$pkgdir"/etc/logrotate.d/fail2ban
	install -Dm644 "$srcdir"/alpine-ssh.jaild \
		"$pkgdir"/etc/fail2ban/jail.d/alpine-ssh.conf
	install -Dm644 "$srcdir"/alpine-sshd.filterd \
		"$pkgdir"/etc/fail2ban/filter.d/alpine-sshd.conf
	install -Dm644 "$srcdir"/alpine-sshd-ddos.filterd \
		"$pkgdir"/etc/fail2ban/filter.d/alpine-sshd-ddos.conf

	chmod o+r "$pkgdir"/usr/lib/python3*/site-packages/fail2ban*.egg-info/*
}

sha512sums="019b088aa6375f98742ed101ef6f65adabca3324444d71d5b8597a8d1d22fa76b9f503660f0498643fe24a3b8e4368de916072a1ab77b8e2ea3eda41c3e0c8c6  fail2ban-0.11.1.tar.gz
2d57fe7a7e3d1889dfa00ac33f5071069ed62f5fc0edb1e1827aedc47fae3a36d19c568b1721ba3a8e117f4ba6b3756d11942f2320b42864d45203f45761c7b6  ec37b1942c4da76f7a0f71efe81bea6835466648.patch
a4dbbcde8ba98368905e06a2d526c662f9087931bc1dab02dd85138d7fcd7d724cfdcee074b454f85def76f1a33d10f0c3b062d9bd777fd52ad73ea45df1dcc8  0001-amend-to-f3dbc9dda10e52610e3de26f538b5581fd905505-ch.patch
1e7581dd04e7777d6fd5c40cc842a7ec5f4e6a0374673d020d89dd61bf4093d48934844bee89bcac9084f9ae44f3beb66e714cf3c2763d79c3e8feb790c5e43b  fail2ban.confd
ee1c229db970239ebc707cd484a650fcf2347c70b411728ee2a4a35a72f4118cfccecf2a221275603320e0332efcc16e4979201933cec1aef1c5d5a082fc4940  fail2ban.logrotate
84915967ae1276f1e14a5813680ee2ebf081af1ff452a688ae5f9ac3363f4aff90e39f8e6456b5c33d5699917d28a16308797095fd1ef9bb1fbcb46d4cea3def  alpine-ssh.jaild
3e8e08d5e349e857b51ce34a9d968f16661b34e1cec06bec0aa9a32723bbe9be5a9890dd479331a9cc860821d33b1bf3b8e995182e319dead5a3d434b1816304  alpine-sshd.filterd
36a81b771be0b36fe0dfb5ee4c72c9cb5b504e110618a8eb6f0f241b4e57d92df01dc5cc04b6b68d5bc6a5e6d68de1000092770285d7a328e5937e50b4b226a3  alpine-sshd-ddos.filterd"
